package com.module.base.widget.skin;

import android.content.Context;
import android.content.res.TypedArray;
import android.util.AttributeSet;

import com.lihang.ShadowLayout;
import com.module.base.R;

import skin.support.content.res.SkinCompatResources;
import skin.support.widget.SkinCompatHelper;
import skin.support.widget.SkinCompatSupportable;

/**
 * @author bsnl_yanxuwen
 * @date 2021/7/23 16:45
 * Description :
 * 换肤的PinEntryEditText
 */
public class SkinShadowLayout extends ShadowLayout implements SkinCompatSupportable {
    private int INVALID_ID = 0;
    private int shadowColor = INVALID_ID;
    private int layoutBackground = INVALID_ID;

    public SkinShadowLayout(Context context) {
        super(context);
    }

    public SkinShadowLayout(Context context, AttributeSet attrs) {
        super(context, attrs);
        initMy(context, attrs, 0);
    }

    public SkinShadowLayout(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
        initMy(context, attrs, defStyle);
    }

    private void initMy(Context context, AttributeSet attrs, int defStyle) {
        TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.ShadowLayout, 0, 0);
        shadowColor = a.getResourceId(R.styleable.ShadowLayout_hl_shadowColor, INVALID_ID);
        layoutBackground = a.getResourceId(R.styleable.ShadowLayout_hl_layoutBackground, INVALID_ID);
        a.recycle();

        applyBorderColorResource();
    }

    private void applyBorderColorResource() {
        //自定义
        try {
            shadowColor = SkinCompatHelper.checkResourceId(shadowColor);
            if (shadowColor != INVALID_ID) {
                int color = SkinCompatResources.getColor(getContext(), shadowColor);
                setShadowColor(color);
            }

            layoutBackground = SkinCompatHelper.checkResourceId(layoutBackground);
            if (layoutBackground != INVALID_ID) {
                int color = SkinCompatResources.getColor(getContext(), layoutBackground);
                super.setLayoutBackground(color);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    @Override
    public void applySkin() {
        applyBorderColorResource();
    }
}
